//
//  FiveTableViewCell.m
//  News
//
//  Created by xalo on 16/3/2.
//  Copyright © 2016年 News. All rights reserved.
//

#import "FiveTableViewCell.h"
#import "PicListModel.h"
#import "UIImageView+WebCache.h"
#import <Reachability.h>

@implementation FiveTableViewCell

-(void)setPicMod:(PicListModel *)picMod {
    
    
    
    _picMod =picMod ;
    
    extern BOOL isWiFiMode;
    Reachability *ablity = [Reachability reachabilityForInternetConnection];
    if (([ablity isReachableViaWiFi])||([ablity isReachable] && !isWiFiMode)||(![ablity  isReachable]) ) {
        
        [self.image1 sd_setImageWithURL:[NSURL URLWithString:picMod.list[0][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
        
        [self.image2  sd_setImageWithURL:[NSURL URLWithString:picMod.list[1][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
        
        [self.image3  sd_setImageWithURL:[NSURL URLWithString:picMod.list[2][@"kpic"]]placeholderImage:[UIImage imageNamed:@"background"]];
    }
    
    
    _title.text = picMod.title ;
    _subTitle.text = picMod.intro ;
    
    
    CGFloat height = [FiveTableViewCell cellOfheightWITString:picMod.intro];
    if (height > 20) {
        CGRect frame = self.subTitle.frame;
        frame.size.height =height;
        self.subTitle.frame =frame;
        
    }
    
    _picMod.cellHeight = self.image1.frame.size.height +self.title.frame.size.height +25 +height ;
    
}

+(CGFloat)cellOfheightWITString:(NSString *)string
{
    
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName];
    
    CGFloat weith = [UIScreen mainScreen].bounds.size.width ;
    
    CGFloat cellWith = weith - 10;
    CGRect bound = [string boundingRectWithSize:CGSizeMake(cellWith, 2000) options:(NSStringDrawingUsesLineFragmentOrigin)attributes:dic context:nil];
    
    return bound.size.height;
}






@end
